home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CASample / CAS_Content.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  5.3 KB  |  205 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CAS_Content.h
  3.  
  4.     Contains:    Data structures and routines to support document content elements
  5.                 and element collections.  A content element in CASample is either
  6.                 a PICT element or an embedded frame.
  7.                 
  8.                 A content element collection implements the element record allocation
  9.                 scheme (currently uses a block allocation scheme)
  10.             
  11.     Written by:    Rick Badertscher
  12.  
  13.     Copyright © 1993-1995 Apple Computer, All rights reserved.
  14.  
  15.     Change History (most recent first):
  16.  
  17.          <2>    11/14/95    RB    Added clipping support
  18.          <1>     9/1/95        RB    Created.
  19. */
  20.  
  21. #if !defined(_H_CAS_Content)
  22. #define _H_CAS_Content
  23.  
  24. #include "CAS_Types.h"
  25.  
  26. //---------------------------------------------------------------------------
  27. //    Forward Declarations
  28. //---------------------------------------------------------------------------
  29.  
  30. //---------------------------------------------------------------------------
  31. //    Content Element Types
  32. //---------------------------------------------------------------------------
  33.  
  34. #define kNULLElemType            'NULL'
  35. #define kFrameElemType            'PART'
  36.  
  37. // ElemColl_FindElem result codes
  38. enum
  39. {
  40.     inElement        = 0,
  41.     inCornerResize    = 1,
  42.     inEdgeResize    = 2
  43. };
  44.  
  45. typedef enum {kNone, kTL, kTR, kBL, kBR, kTE, kBE, kRE, kLE} ResizeHandle;
  46.  
  47. #define    kBorderWidth    5
  48.  
  49. //---------------------------------------------------------------------------
  50. //    Data Structures
  51. //---------------------------------------------------------------------------
  52.  
  53. typedef struct
  54. {
  55.     RgnHandle    cornerHandleRgn;
  56.     RgnHandle    edgeHandleRgn;
  57.     RgnHandle    selectRgn;
  58. } SelRgnRec, *SelRgnRecPtr;
  59.  
  60.  
  61. // Element Record
  62.  
  63. struct    ElemRec
  64. {
  65.     OSType                elemType;
  66.     Handle                elemData;
  67.     Boolean                resizable;
  68.     Boolean                selected;
  69.     Point                location;
  70.     Rect                contentRect;        // In document coordinates
  71.     SelRgnRec            selRgn;
  72.     ElemCollPtr            collection;
  73.     Boolean                visible;
  74.     RgnHandle            clipRgn;
  75.     Boolean                clipInvalid;
  76. };
  77.  
  78.  
  79. // Element Node
  80.  
  81. struct ElemNode
  82. {
  83.     ElemPtr                elemPtr;
  84.     ElemNodePtr            nextNode;
  85. };
  86.  
  87. struct ElemList
  88. {
  89.     ElemNodePtr            headNode;
  90.     ElemNodePtr            tailNode;
  91.     short                count;
  92. };
  93.  
  94. // Element Collection
  95.  
  96. struct ElemColl
  97. {
  98.     DocPtr                docPtr;
  99.     short                count;
  100.     ElemList            elemList;
  101. };
  102.  
  103.  
  104. // a ElemPtr is passed to each routine, theElem can be either rellocatable or not
  105.  
  106. ElemPtr            Elem_New (                Handle            data,
  107.                                         OSType            type,
  108.                                         Rect            contentRect,
  109.                                         Point            location);
  110.  
  111. ElemPtr            Elem_Read (                IOStreamPtr ioStream);
  112.  
  113.  
  114. OSErr            Elem_Write (            ElemPtr, IOStreamPtr ioStream);
  115. long            Elem_SpaceRequired(        ElemPtr);
  116. ElemPtr            Elem_Clone (            ElemPtr);
  117.  
  118. void            Elem_UpdateCAFrame(        ElemPtr);
  119. void            Elem_UpdateCAVisFrame(    ElemPtr);
  120.  
  121. void            Elem_Remove(            ElemPtr);
  122. void            Elem_Free(                ElemPtr);
  123.  
  124. void            Elem_GetLocation(        ElemPtr, Point* location);
  125. void            Elem_SetLocation(        ElemPtr, Point location);
  126.  
  127. void            Elem_SetRect(            ElemPtr, Rect contentRect);
  128. void            Elem_GetRect(            ElemPtr, Rect* contentRect);
  129. void            Elem_GetLocatedRect(    ElemPtr, Rect* contentRect);
  130. void            Elem_GetDisplayRect(    ElemPtr, Rect* displayRect);
  131.  
  132. void            Elem_SetSelected(        ElemPtr, Boolean selected);
  133. Boolean            Elem_GetSelected(        ElemPtr);
  134.  
  135. OSType            Elem_GetType(            ElemPtr);
  136.  
  137. void            Elem_SetVisible(        ElemPtr    theElem, Boolean visible);
  138.  
  139. void            Elem_Invalidate(        ElemPtr);
  140. void            Elem_Draw(                ElemPtr, Boolean drawSel);
  141.  
  142. void            Elem_InvalClipRgn (        ElemPtr);
  143. void            Elem_CalcClipRgn(        ElemPtr);
  144.  
  145. void            Elem_DrawSelRgn(        ElemPtr);
  146. void            Elem_InvalSelRgn(        ElemPtr);
  147. void            Elem_CalcSelRgn(        ElemPtr);
  148.  
  149. Boolean            Elem_HandleMouseDown(    ElemPtr, DocPtr, EventRecord*);
  150.  
  151. void            Elem_HandleMouseInCornerResize (    ElemPtr            elem,
  152.                                                     DocPtr            docPtr,
  153.                                                     Point*            mouse,
  154.                                                     EventRecord*    event);
  155.                                                     
  156. void            Elem_HandleMouseInEdgeResize (        ElemPtr            theElem,
  157.                                                     DocPtr            theDoc,
  158.                                                     Point*            mouse,
  159.                                                     EventRecord*    event);
  160.                                         
  161.  
  162. // Element Collection
  163. void            ElemColl_Init(                ElemCollPtr, DocPtr theDoc);
  164.  
  165. void            ElemColl_AddElem(            ElemCollPtr, ElemPtr theElem);
  166. void            ElemColl_AddElemTemp(        ElemCollPtr, ElemPtr theElem);
  167.  
  168. void            ElemColl_Free(                ElemCollPtr);
  169. void            ElemColl_FreeAll(            ElemCollPtr);
  170.     
  171. void            ElemColl_ClipElements(        ElemCollPtr, Rect* clipArea);
  172. void            ElemColl_RemoveElem(        ElemCollPtr, ElemPtr theElem);
  173. short            ElemColl_GetCount(            ElemCollPtr);
  174. ElemPtr            ElemColl_GetNthElem(        ElemCollPtr, short index);
  175.  
  176. short            ElemColl_GetCountOfType(    ElemCollPtr, OSType elemType);
  177. ElemPtr            ElemColl_GetNthElemOfType(    ElemCollPtr, short index, OSType type);
  178.  
  179. short            ElemColl_FindElem(            ElemCollPtr, Point mouse, ElemPtr* theElem);
  180. DocPtr            ElemColl_GetDocPtr(            ElemCollPtr);
  181.  
  182. // Z-order functions.
  183. void            ElemColl_MoveElemToFront(    ElemCollPtr, ElemPtr);
  184. void            ElemColl_GetRgnOverElem(    ElemCollPtr, ElemPtr, RgnHandle);
  185.  
  186. ElemListPtr        ElemColl_GetCurrentSelection (ElemCollPtr);
  187.  
  188. // ElemList
  189. //
  190. // An ElemList is a single linked list of ElemNode structures.
  191. // The list order represents the zorder.  The tail node is the top most layer.
  192.  
  193. void            ElemList_Init (                ElemListPtr theList);
  194. void            ElemList_Free(                ElemListPtr theList);
  195. void            ElemList_AddNode (            ElemListPtr theList, ElemNodePtr theNode);
  196. ElemNodePtr        ElemList_RemoveNode (        ElemListPtr theList, ElemPtr theElem);
  197. ElemNodePtr        ElemList_GetNode (            ElemListPtr theList, ElemPtr theElem);
  198. ElemNodePtr        ElemList_GetHeadNode (        ElemListPtr theList);
  199. short            ElemList_GetCount(            ElemListPtr);
  200. ElemPtr            ElemList_GetNthElem(        ElemListPtr, short index);
  201.  
  202.  
  203. #endif
  204.  
  205.